package Leetcode;

import tree.TreeNode;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class maxPathSum {
    int max = Integer.MIN_VALUE;
    public int maxPathSum(TreeNode root) {
        maxPath(root);
        return max;
    }
    public int maxPath(TreeNode root){
        if (root == null){
            return 0;
        }
        int left = Math.max(maxPath(root.left), 0);
        int right = Math.max(maxPath(root.right), 0);
        int count = root.val + left + right;
        max = Math.max(max, count);
        return root.val + Math.max(left, right);
    }
}
